package kz.edu.sdu.itech.pcs.common;

public abstract class Client implements Runnable {
   public static boolean STOP = false;
   public static String NOT_STARTED = "NOT STARTED";
   public static String WORKING = "WORKING";
   public static String DONE = "DONE";
   public static String STOPED = "STOPED";

   protected String title;
   protected Alphabet alphabet;
   protected int len;
   protected int hash;
   protected long start, end, current;

   protected String status = NOT_STARTED;
   protected Integer count = Integer.valueOf(0);

   public double getPercentage() {
      double all = end - start;
      double cur = current - start;
      return (cur * 100 / all);
   }

   public String getTitle() {
      return title;
   }

   public void setTitle(String title) {
      this.title = title;
   }

   public Alphabet getAlphabet() {
      if (alphabet == null) {
         alphabet = new Alphabet();
      }
      return alphabet;
   }

   public void setAlphabet(Alphabet alphabet) {
      this.alphabet = alphabet;
   }

   public int getLen() {
      return len;
   }

   public void setLen(int len) {
      this.len = len;
   }

   public int getHash() {
      return hash;
   }

   public void setHash(int hash) {
      this.hash = hash;
   }

   public long getStart() {
      return start;
   }

   public void setStart(long start) {
      this.start = start;
   }

   public long getEnd() {
      return end;
   }

   public void setEnd(long end) {
      this.end = end;
   }

   public long getCurrent() {
      return current;
   }

   public void setCurrent(long current) {
      this.current = current;
   }

   public String getStatus() {
      return status;
   }

   public void setStatus(String status) {
      this.status = status;
   }

   public Integer getCount() {
      return count;
   }

   public void setCount(Integer count) {
      this.count = count;
   }

   @Override
   public String toString() {
      if (alphabet != null) {
         return String.format("name=%s, alf=%s, hash=%d, count=%d, start=%d, end=%d, current=%d", title, alphabet.toString(), hash, count, start, end, current);
      } else {
         return String.format("name=%s", title);
      }
   }

}
